#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
每个常量都是class的一个唯一实例。Python提供了Enum类来实现这个功能
value属性则是自动赋给成员的int常量，默认从1开始计数。
"""
from enum import Enum, unique

Month = Enum('Month', ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'))

for name, member in Month.__members__.items():
    print(name, '=>', member, ',', member.value)


@unique        # 检查Nonth类中是否有重复值
class Nonth(Enum):
    Jan = 1
    Feb = 2
    Mar = 3
    Apr = 4
    May = 5
    Jun = 6
    Jul = 7
    Aug = 8
    Sep = 9
    Oct = 10
    Nov = 11
    Dec = 12


print(Nonth.Jan)    # Nonth.Jan
print(Nonth.Jan.value)  # 30
print(Nonth.Jun.value)
print(Nonth(10))

for name, member in Nonth.__members__.items():
    print(name, '-->', member, '==>', member.value)
